package com.relife.common.quartz;

import org.quartz.JobDetail;
import org.quartz.Scheduler;

public class QuartzMis {
	private static String JOB_GROUP_NAME = "MIS_JOBGROUP_NAME";
	private static String TRIGGER_GROUP_NAME = "MIS_TRIGGERGROUP_NAME";

	/**
	 * 
	 * @param sched
	 * @param jobName
	 * @param cls
	 * @param time
	 */
	public static void addJob(Scheduler sched, CronTriggerMis trigger) {
		try {
			JobDetail jobDetail = new JobDetail(trigger.getName(), JOB_GROUP_NAME, MisJob.class);// 任务名，任务组，任务执行类
			trigger.setGroup(TRIGGER_GROUP_NAME);
			// 触发器
			sched.scheduleJob(jobDetail, trigger);
			// 启动
			if (!sched.isShutdown()) {
				sched.start();
			}
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

	/**
	 * 
	 * @param sched
	 * @param jobName
	 */
	public static void removeJob(Scheduler sched, String jobName) {
		try {
			sched.pauseTrigger(jobName, JOB_GROUP_NAME);// 停止触发器
			sched.unscheduleJob(jobName, JOB_GROUP_NAME);// 移除触发器
			sched.deleteJob(jobName, JOB_GROUP_NAME);// 删除任务
		} catch (Exception e) {
			throw new RuntimeException(e);
		}
	}

}
